package com.sky.mapper;

import com.sky.vo.AddressBookVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface AddressBookMapper {

    /**
     * 新增地址
     *
     * @param addressBookVO
     */
    void insert(AddressBookVO addressBookVO);

    /**
     * 查询当前登录用户的所有地址信息
     *
     * @param userId
     * @return
     */

    List<AddressBookVO> selectByUserId(Long userId);

    /**
     * 查询默认地址
     *
     * @param userId
     * @return {@link AddressBookVO}
     */
    @Select("select * from address_book where user_id = #{userId} and is_default = 1")
    AddressBookVO selectDefaultByUserId(Long userId);

    /**
     * 根据id查询地址
     *
     * @param id
     * @return {@link AddressBookVO}
     */
    @Select("select * from address_book where id = #{id}")
    AddressBookVO selectAddressById(Long id);

    /**
     * 根据id修改地址
     *
     * @param addressBookVO
     */
    void update(AddressBookVO addressBookVO);

    /**
     * 根据id删除地址
     *
     * @param id
     */
    @Delete("delete from address_book where id = #{id}")
    void delete(Long id);


    void updateDefaultAddress(AddressBookVO addressBookVO);
}
